<?php
/*
 * Created on 11 24, 09
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
defined('_JEXEC') OR defined('_VALID_MOS') OR die('...Direct Access to this location is not allowed...');
### @copyright Copyright (C) 2006-2010 Joobi Limited All rights reserved.
### @license This file is released under the GNU GPL2 license (http://www.gnu.org/licenses )

//if(!defined('ACA_JPATH_ROOT')){
//	if ( defined('JPATH_ROOT') AND class_exists('JFactory')) {
//		define ('ACA_JPATH_ROOT' , JPATH_ROOT );
//		if(!defined('ACA_CMSTYPE')){//mary
//			define( 'ACA_CMSTYPE', true );
//		}//endif mary
//	}else{
//		define ('ACA_JPATH_ROOT' , $GLOBALS['mosConfig_absolute_path'] );
//		define( 'ACA_CMSTYPE', false );
//	}
//	require_once( ACA_JPATH_ROOT . '/components/com_acajoom/defines.php');
//}

class captcha{

 function encryptData($original_text, $password) {
 	if(empty($key)){//check if key is empty
 		$key='';
 	}
    $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $enc_base64 = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, $key, $original_text, MCRYPT_MODE_ECB, $iv));
    return $enc_base64;
  }//endfunction

  function generateCode($characters) {
		/* list all possible characters, similar looking characters and vowels have been removed */
		$possible = '23456789bcdfghjkmnpqrstvwxyz';
		$code = '';
		$i = 0;
		while ($i < $characters) {
			$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
			$i++;
		}
		return $code;
	}//endfct

  function decryptData($encoded_text, $password) {
  	if(empty($key)){
			$key='';
	}
    $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $original = trim(mcrypt_decrypt(MCRYPT_XTEA, $key, base64_decode($encoded_text), MCRYPT_MODE_ECB, $iv), "\0");
    return $original;
  }

}//endclass

?>
